package com.zy.socket.testfile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/**
 * @Author Gong
 * @Description 客户端接到文件存储
 * @dATE 2021/12/19 14:44
 **/
public class Client {
    public static void main(String[] args) {
        try {
             Socket socket = new Socket("127.0.0.1", 9999);
            InputStream inputStream = socket.getInputStream();

            FileOutputStream fileOutputStream = new FileOutputStream(new File("d:/temp/java_xx.png"));

            byte[] buffer = new byte[1024];
            int len;
            while ((len= inputStream.read(buffer)) > -1){
                fileOutputStream.write(buffer,0,len);
            }
            System.out.println("客户端文件接收完毕。");

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
